﻿using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Linq;
using System.Web;
using teacher.Util;

namespace teacher.DAL
{
    public class GrowDAL
    {
        /// <summary>
        /// 保存成长档案发表的小视频
        /// </summary>
        /// <param name="userId"></param>
        /// <param name="word"></param>
        /// <param name="schoolId"></param>
        /// <param name="classId"></param>
        /// <param name="videoURL"></param>
        /// <param name="videoImgURL"></param>
        /// <returns></returns>
        public int AddGrowVideo(string userId, string word, string schoolId, string classId, string videoURL, string videoImgURL)
        {
            List<SqlParameter> paramelist = new List<SqlParameter>();
            paramelist.Add(new SqlParameter("@userId", userId));
            paramelist.Add(new SqlParameter("@status", 1));
            paramelist.Add(new SqlParameter("@schoolId", schoolId));
            paramelist.Add(new SqlParameter("@classId", classId));
            paramelist.Add(new SqlParameter("@videoURL", videoURL));
            string words_sql = "";
            string wordsParame = "";
            if (!string.IsNullOrEmpty(word) && !string.IsNullOrWhiteSpace(word))
            {
                words_sql = ",[words]";
                wordsParame = ",@words";
                paramelist.Add(new SqlParameter("@words", word));
            }
            string videoImgURL_sql = "";
            string videoImgURLParame = "";
            if (!string.IsNullOrEmpty(videoImgURL) && !string.IsNullOrWhiteSpace(videoImgURL))
            {
                videoImgURL_sql = ",[videoImgURL]";
                videoImgURLParame = ",@videoImgURL";
                paramelist.Add(new SqlParameter("@videoImgURL", videoImgURL));
            }
            string sql = "INSERT INTO [dbo].[T_Grow]([id],[userId]" + words_sql + ",[creatTime],[status],[schoolId],[classId],[videoURL]" + videoImgURL_sql + ") VALUES(NEWID(),@userId" + wordsParame + ",GETDATE(),@status,@schoolId,@classId,@videoURL" + videoImgURLParame + ")";
            SqlParameter[] parames = paramelist.ToArray();
            int count = SQLHepler.ExecuteSql(sql, parames);
            return 1;
        }
    }
}